package cn.livingCloud.dto;

import org.hyperic.sigar.FileSystem;
import org.hyperic.sigar.Sigar;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 唐旭 on 2016/7/5.
 */
public class SystemProfileDto {
    //CPU 使用率
    private double cpuUsedPerc;
    //内存已使用
    private double memUsed;
    //内存总共
    private double memTotal;
    //内存使用百分比
    private double memUsedPerc;
    private String memUsedStr;
    private String memTotalStr;
    private String memUsedPercStr;

    private String fqdn;

    private List<FileSystemDto> fileSystems = new ArrayList<>();


    public SystemProfileDto(Sigar sigar) {
        try {
            cpuUsedPerc = sigar.getCpuPerc().getCombined();//cpu

            memUsed = sigar.getMem().getActualUsed();//mem
            memTotal = sigar.getMem().getTotal();
            memUsedPerc = sigar.getMem().getUsedPercent();

            memUsedStr = String.format("%.2f", memUsed / 1024 / 1024 / 1024) + "GB";
            memTotalStr = String.format("%.2f", memTotal / 1024 / 1024 / 1024) + "GB";
            memUsedPercStr = String.format("%.2f", memUsedPerc) + "%";

            fqdn = sigar.getFQDN();//IP地址

            // 取硬盘已有的分区及其详细信息
            for (FileSystem fs : sigar.getFileSystemList()) {
                fileSystems.add(new FileSystemDto(fs, sigar));
            }
        } catch (Exception e) {
            //ignore
        }
    }


    public double getCpuUsedPerc() {
        return cpuUsedPerc;
    }

    public SystemProfileDto setCpuUsedPerc(double cpuUsedPerc) {
        this.cpuUsedPerc = cpuUsedPerc;
        return this;
    }

    public String getFqdn() {
        return fqdn;
    }

    public SystemProfileDto setFqdn(String fqdn) {
        this.fqdn = fqdn;
        return this;
    }

    public double getMemTotal() {
        return memTotal;
    }

    public SystemProfileDto setMemTotal(double memTotal) {
        this.memTotal = memTotal;
        return this;
    }

    public String getMemTotalStr() {
        return memTotalStr;
    }

    public SystemProfileDto setMemTotalStr(String memTotalStr) {
        this.memTotalStr = memTotalStr;
        return this;
    }

    public double getMemUsed() {
        return memUsed;
    }

    public SystemProfileDto setMemUsed(double memUsed) {
        this.memUsed = memUsed;
        return this;
    }

    public double getMemUsedPerc() {
        return memUsedPerc;
    }

    public SystemProfileDto setMemUsedPerc(double memUsedPerc) {
        this.memUsedPerc = memUsedPerc;
        return this;
    }

    public String getMemUsedPercStr() {
        return memUsedPercStr;
    }

    public SystemProfileDto setMemUsedPercStr(String memUsedPercStr) {
        this.memUsedPercStr = memUsedPercStr;
        return this;
    }

    public String getMemUsedStr() {
        return memUsedStr;
    }

    public SystemProfileDto setMemUsedStr(String memUsedStr) {
        this.memUsedStr = memUsedStr;
        return this;
    }

    public List<FileSystemDto> getFileSystems() {
        return fileSystems;
    }

    public SystemProfileDto setFileSystems(List<FileSystemDto> fileSystems) {
        this.fileSystems = fileSystems;
        return this;
    }
}
